#include <bits/stdc++.h>
#define int long long
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define endl "\n"
#define INF 1e18
#define PII pair<int,int>
#define fi first
#define se second
#define pb push_back
using namespace std;
int T;
int n;
struct point{
    bool color;
    int num;
}va[200010];
int cnt=0,maxn=-1;
int solve(int x){
    for(int i=x-1;i>=1;i--){
        if(va[i].color==va[x].color){
            if(va[i].num==va[x].num)return va[i].num;
            else return 0;
        }
    }
    return 0;
}
void dfs(int idx,int op){
    if(idx==n){
        cnt=0;
        for(int i=1;i<=15;i++)cnt+=solve(i);
        maxn=max(cnt,maxn);
        return;
    }
    va[idx].color=op;
    dfs(idx+1,0);
    dfs(idx+1,1);
}
signed main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    cin>>T;
    while(T--){
        cnt=0;
        maxn=-1;
        cin>>n;
        for(int i=1;i<=n;i++){
            cin>>va[i].num;
        }
        dfs(1,0);
        dfs(1,1);
        cout<<maxn<<"\n";
    }
    return 0;
}
